/*
 * Copyright 2018 Shanxi Lu'an Taihang Laihui Net Tech co.,LTD.
 */
package com.wei;

import sun.applet.Main;

/**
 * Description:
 *
 * @author wzz
 * @since: 1.0
 * Create Date Time: 2018/11/3 17:46
 * Update Date Time:
 */
public class MyThread2 {

    private static int num = 0;
    public static synchronized  void printNum(String str){

        if("a".equals(str)){
            num = 100;
            System.out.println("执行a");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }else{
            num = 200;
            System.out.println("执行b");
        }

        System.out.println("num="+num);
    }

    public static void main(String[] args) {
        MyThread2 m1 = new MyThread2();
        MyThread2 m2 = new MyThread2();

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                m1.printNum("a");
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                m2.printNum("b");
            }
        });
        t1.start();
        t2.start();
    }
}
